/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sgep.tools;

/**
 *
 * @author Administrator
 */
public class Json {
    
    /**
     * 属性名常量
     */
    final static public String MsgTitle = "title";
    final static public String MsgContent = "msg";
    final static public String Answer = "answer";
    
    /**
     * 属性值常量
     */
    final static public int Informantion = 1;//这3个值用于指定客户端js选择什么方式显示消息，例如用alert()显示错误消息，用Tip显示登录成功消息
    final static public int ModalMessageBox = 2;
    final static public int NonModalMessageBox = 3;
    
    private String text = null;

    public Json() {
    }

    public Json(String key, Object value) {
        this.add(key, value);
    }

    public Json(String key, String value) {
        this.add(key, value);
    }

    public void add(String key, Object value) {
        if (text == null) {
            if (value instanceof String) {
                text = "{" + key + ":'" + value.toString() + "'}";
            } else {
                text = "{" + key + ":" + value.toString() + "}";
            }
        } else {
            text = text.substring(0, text.length() - 1);
            if (value instanceof String) {
                text += "," + key + ":'" + value.toString() + "'}";
            } else {
                text += "," + key + ":" + value.toString() + "}";
            }
        }
    }

    @Override
    public String toString() {
        return text;
    }
}
